package org.dromara.crawler.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.crawler.domain.SiteManager;
import org.dromara.crawler.service.SiteManagerService;
import org.springframework.web.bind.annotation.*;

/**
 * 站点管理模块接口
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/siteManager")
public class SiteManagerController {

    private final SiteManagerService siteManagerService;

    /**
     * 站点信息查询
     */
    @GetMapping("/queryById/{siteId}")
    public R<SiteManager> queryById(@PathVariable Long siteId) {
        return R.ok(siteManagerService.findById(siteId));
    }

    /**
     * 站点分页查询
     */
    @GetMapping("/queryByPage")
    public R<IPage<SiteManager>> queryByPage(SiteManager siteManager, PageQuery pageQuery) {
        return R.ok(siteManagerService.queryByPage(siteManager, pageQuery));
    }

    /**
     * 站点新增
     */
    @PostMapping("/add")
    public R<Boolean> add(@RequestBody SiteManager siteManager) {
        return R.ok(siteManagerService.save(siteManager));
    }

    /**
     * 站点编辑
     */
    @PutMapping("/edit")
    public R<Boolean> edit(@RequestBody SiteManager templateManager) {
        return R.ok(siteManagerService.updateById(templateManager));
    }

    /**
     * 站点删除
     */
    @DeleteMapping("/delete/{siteId}")
    public R<Boolean> delete(@PathVariable Long siteId) {
        return R.ok(siteManagerService.removeById(siteId));
    }


}
